
import java.util.LinkedList;
// 226 - 反转二叉树
class Solution {
    public TreeNode invertTree(TreeNode root) {
        if(root == null){
            return null;
        }
        TreeNode left = invertTree(root.left);
        TreeNode right = invertTree(root.right);
        root.left = right;
        root.right = left;
        return root;
    }
}
class Solution {
    public TreeNode invertTree(TreeNode root) {
        if(root == null){
            return null;
        }
        Queue<TreeNode> node = new LinkedList<>();
        node.offer(root);
        while(!node.isEmpty()){
            TreeNode tmp = node.poll();
            root.left = root.right;
            root.right = tmp;
            if(root.right != null){
                node.offer(root.right);
            }
            if(root.left != null){
                node.offer(root.left);
            }
        }
        return root;
    }
}
public class Test {
}
